package cn.pink.gamesrv.account;

import cn.pink.common.support.tools.global.GlobalTool;
import cn.pink.core.CallPoint;
import cn.pink.core.Port;
import cn.pink.core.Session;
import cn.pink.core.support.Param;
import cn.pink.gamesrv.RPCProxy.GameServiceProxy;

/**
 * 账号管理器
 * @Author: pink
 * @Date: 2022/6/30 17:58
 */
public class AccountManager {
    /**
     * 角色登陆
     */
    public static void roleLogin(AccountObject accObj, String humanId, AccountService serv) {
        Session session = GlobalTool.getInstance().getSession(humanId);

        CallPoint gamePoint = new CallPoint();

        //登录前check 其他game是否存在角色 存在直接发到原来玩家在线的game登录
        if(session != null) {
            gamePoint.nodeId = session.getGamePoint().nodeId;
            gamePoint.portId = session.getGamePoint().portId;
        }
        else {
            Port port = Port.getCurrent();

            gamePoint.nodeId = port.getNodeId();
            gamePoint.portId = port.getId();
        }

        // 开始角色登陆
        GameServiceProxy proxy = GameServiceProxy.newInstance(gamePoint.nodeId, gamePoint.portId);
        proxy.roleLogin(accObj.getSessionPoint(), humanId, accObj.getUserIdentity(), accObj.getToken());

        proxy.listenResult((Param result, Param context) -> {
            //TODO 带角色登录 删除 AccountObj

            System.out.println("---------------------- 删除 AccountObj");
        });
    }
}
